/**
 * Copyright (C) 2015. Keegan小钢（http://keeganlee.me）
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.rockcent.action.impl;

import android.content.Context;
import android.os.AsyncTask;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.rockcent.action.AppAction;
import com.rockcent.action.CallbackListener;
import com.rockcent.action.ErrorEvent;
import com.rockcent.api.ApiResponse;
import com.rockcent.api.KcuponApi;
import com.rockcent.api.XYApi;
import com.rockcent.api.impl.KcuponApiImpl;
import com.rockcent.api.impl.XYApiImpl;
import com.rockcent.api.utils.NetworkTask;
import com.rockcent.api.utils.ReturnCode;
import com.rockcent.model.AddressModel;
import com.rockcent.model.BClientCustomerBO;
import com.rockcent.model.CommentModel;
import com.rockcent.model.ContourMap;
import com.rockcent.model.CouponBO;
import com.rockcent.model.CouponModel;
import com.rockcent.model.CouponStore;
import com.rockcent.model.CustCouponOrderBO;
import com.rockcent.model.CustomerBO;
import com.rockcent.model.CustomerCouponBO;
import com.rockcent.model.CustomerIncomeBO;
import com.rockcent.model.DeliveryModel;
import com.rockcent.model.IndustryGroupModel;
import com.rockcent.model.MessageBO;
import com.rockcent.model.OrderInfo;
import com.rockcent.model.OrderModel;
import com.rockcent.model.SchoolModel;
import com.rockcent.model.Topics;
import com.rockcent.model.VerificationModel;
import com.rockcent.model.WalletModel;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * AppAction接口的实现类
 *
 * @version 1.0 创建时间：15/6/25
 */
public class AppActionImpl implements AppAction {

    private final static int LOGIN_OS = 1; // 表示Android
    private final static int PAGE_SIZE = 20; // 默认每页20条

    private Context context;
    private XYApi xyApi;
    private KcuponApi kcuponApi;

    private static volatile AppActionImpl appActionImpl;
    public final static String REG = "^[1]([3][0-9]{1}|[5][0-9]{1}|[8][0-9]{1}|[7][0-9]{1}|[4][0-9]{1})[0-9]{8}$";//验证码正则表达式


    private AppActionImpl(Context context, String xyApiAddress, String qkApiAddress) {
        this.context = context;
        this.xyApi = new XYApiImpl(xyApiAddress);
        this.kcuponApi = new KcuponApiImpl(qkApiAddress);
    }

    public static AppActionImpl getInstance(Context context, String xyApiAddress, String qkApiAddress) {
        if (appActionImpl == null) {
            synchronized (AppActionImpl.class) {
                appActionImpl = new AppActionImpl(context, xyApiAddress, qkApiAddress);
            }
        }
        return appActionImpl;
    }

    @Override
    public void listCustomerCouponsForPage(final String xyCustomerId, final String searchKey, final int currentPage, final int pageSize, final CallbackListener<List<CustomerCouponBO>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<CustomerCouponBO>>>() {

            @Override
            protected ApiResponse<List<CustomerCouponBO>> doInBackground(Void... voids) {
                return xyApi.listCustomerCouponsForPage(xyCustomerId, searchKey, currentPage, pageSize);
            }

            @Override
            protected void onPostExecute(ApiResponse<List<CustomerCouponBO>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void queryIndustryGroup(final CallbackListener<List<IndustryGroupModel>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<IndustryGroupModel>>>() {

            @Override
            protected ApiResponse<List<IndustryGroupModel>> doInBackground(Void... voids) {
                return kcuponApi.queryIndustryGroup();
            }

            @Override
            protected void onPostExecute(ApiResponse<List<IndustryGroupModel>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void listHotCoupon(final int pageSize, final int currentPage, final CallbackListener<List<CouponModel>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<CouponModel>>>() {

            @Override
            protected ApiResponse<List<CouponModel>> doInBackground(Void... voids) {
                return kcuponApi.listHotCoupon(pageSize, currentPage);
            }

            @Override
            protected void onPostExecute(ApiResponse<List<CouponModel>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void editCoupon(final String obj, final CallbackListener<Boolean> listener) {
        new AsyncTask<Void, Void, ApiResponse<Boolean>>() {

            @Override
            protected ApiResponse<Boolean> doInBackground(Void... voids) {
                return xyApi.editCoupon(obj);
            }

            @Override
            protected void onPostExecute(ApiResponse<Boolean> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void publishCoupon(final String obj, final CallbackListener<Integer> listener) {
        new AsyncTask<Void, Void, ApiResponse<Integer>>() {

            @Override
            protected ApiResponse<Integer> doInBackground(Void... voids) {
                return xyApi.publishCoupon(obj);
            }

            @Override
            protected void onPostExecute(ApiResponse<Integer> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void upload(final String file, final String fileName, final CallbackListener<String> listener) {
        new AsyncTask<Void, Void, ApiResponse<String>>() {

            @Override
            protected ApiResponse<String> doInBackground(Void... voids) {
                return kcuponApi.upload(file, fileName);
            }

            @Override
            protected void onPostExecute(ApiResponse<String> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void behavior(final String topicId, final String customerId, final String behaviorType, final CallbackListener<Void> listener) {
        new AsyncTask<Void, Void, ApiResponse<Boolean>>() {

            @Override
            protected ApiResponse<Boolean> doInBackground(Void... voids) {
                return xyApi.behavior(topicId, customerId, behaviorType);
            }

            @Override
            protected void onPostExecute(ApiResponse<Boolean> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }
    @Override
    public void getVerificationDelivery(final int verificationId, final CallbackListener<DeliveryModel> listener) {
        new AsyncTask<Void, Void, ApiResponse<DeliveryModel>>() {

            @Override
            protected ApiResponse<DeliveryModel> doInBackground(Void... voids) {
                return kcuponApi.getVerificationDelivery(verificationId);
            }

            @Override
            protected void onPostExecute(ApiResponse<DeliveryModel> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void addFavorite(final String loginName, final int couponModelId, final CallbackListener<Void> listener) {
        new AsyncTask<Void, Void, ApiResponse<Void>>() {

            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return kcuponApi.addFavorite(loginName, couponModelId);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void addComment(final String orderId, final String loginName, final int couponModelId, final int score, final String content, final String isHidden, final int verificationId, final CallbackListener<Void> listener) {
        new AsyncTask<Void, Void, ApiResponse<Void>>() {

            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return kcuponApi.addComment(orderId, loginName, couponModelId, score, content, isHidden, verificationId);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void endVerificationDelivery(final int verificationId, final CallbackListener<Void> listener) {
        new AsyncTask<Void, Void, ApiResponse<Void>>() {

            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return kcuponApi.endVerificationDelivery(verificationId);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void getTopics(final int currentPage, final int pageSize, final String type, final CallbackListener<List<Topics>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<Topics>>>() {

            @Override
            protected ApiResponse<List<Topics>> doInBackground(Void... voids) {
                return xyApi.getTopics(currentPage, pageSize, type);
            }

            @Override
            protected void onPostExecute(ApiResponse<List<Topics>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void getPositonBySchool(final int schoolId, final CallbackListener<AddressModel> listener) {
        new AsyncTask<Void, Void, ApiResponse<AddressModel>>() {

            @Override
            protected ApiResponse<AddressModel> doInBackground(Void... voids) {
                return xyApi.getPositionBySchool(schoolId);
            }

            @Override
            protected void onPostExecute(ApiResponse<AddressModel> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void listComment(final int couponModelId, final int currentPage, final int pageSize, final CallbackListener<List<CommentModel>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<CommentModel>>>() {

            @Override
            protected ApiResponse<List<CommentModel>> doInBackground(Void... voids) {
                return xyApi.listComment(couponModelId, currentPage, pageSize);
            }

            @Override
            protected void onPostExecute(ApiResponse<List<CommentModel>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void viewCouponModel(final int couponModelId, final String loginName, final int channelId, final CallbackListener<CouponModel> listener) {
        new AsyncTask<Void, Void, ApiResponse<CouponModel>>() {

            @Override
            protected ApiResponse<CouponModel> doInBackground(Void... voids) {
                return kcuponApi.viewCouponModel(couponModelId, loginName, channelId);
            }

            @Override
            protected void onPostExecute(ApiResponse<CouponModel> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void getContour(final CallbackListener<List<ContourMap>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<ContourMap>>>() {

            @Override
            protected ApiResponse<List<ContourMap>> doInBackground(Void... voids) {
                return kcuponApi.getContour();
            }

            @Override
            protected void onPostExecute(ApiResponse<List<ContourMap>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void initPayPass(final String loginName, final String loginPassword, final String payPassword, final CallbackListener<Void> listener) {
        new AsyncTask<Void, Void, ApiResponse<Void>>() {

            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return kcuponApi.initPayPass(loginName, loginPassword, payPassword);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void resetLoginPassword(final String loginName, final String password, final String code, final CallbackListener<Void> listener) {
        new AsyncTask<Void, Void, ApiResponse<Void>>() {

            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return kcuponApi.findPassByPhone(loginName, password, code);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void getCustomer(final String loginName, final String xyCustomerId, final String customerId, final CallbackListener<CustomerBO> listener) {
        new AsyncTask<Void, Void, ApiResponse<CustomerBO>>() {

            @Override
            protected ApiResponse<CustomerBO> doInBackground(Void... voids) {
                return xyApi.getCustomer(loginName, xyCustomerId, customerId);
            }

            @Override
            protected void onPostExecute(ApiResponse<CustomerBO> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void getBClientCustomer(final String loginName, final CallbackListener<BClientCustomerBO> listener) {
        new AsyncTask<Void, Void, ApiResponse<BClientCustomerBO>>() {

            @Override
            protected ApiResponse<BClientCustomerBO> doInBackground(Void... voids) {
                return kcuponApi.getBClientCustomer(loginName);
            }

            @Override
            protected void onPostExecute(ApiResponse<BClientCustomerBO> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void getSchool(final CallbackListener<List<SchoolModel>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<SchoolModel>>>() {

            @Override
            protected ApiResponse<List<SchoolModel>> doInBackground(Void... voids) {
                return xyApi.getSchools();
            }

            @Override
            protected void onPostExecute(ApiResponse<List<SchoolModel>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void registerByPhone(final String phoneNum, final String code, final int schoolId, final String password, final CallbackListener<Void> listener) {
        if (TextUtils.isEmpty(phoneNum)) {
            listener.onFinish();
            listener.onFailure(ReturnCode.C_PARAM_NULL, "手机号码为空");
            return;
        }
        if (TextUtils.isEmpty(password) || password.length() > 15 || password.length() < 6) {
            listener.onFinish();
            listener.onFailure(ReturnCode.C_PARAM_NULL, "请输入6-15位密码");
            return;
        }
        if (TextUtils.isEmpty(code)) {
            listener.onFinish();
            listener.onFailure(ReturnCode.C_PARAM_NULL, "验证码为空");
            return;
        }
        new AsyncTask<Void, Void, ApiResponse<Void>>() {
            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return xyApi.registerByPhone(phoneNum, code, password, schoolId);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> voidApiResponse) {
                super.onPostExecute(voidApiResponse);
                if (listener != null && voidApiResponse != null) {
                    if (voidApiResponse.isSuccess()) {
                        listener.onSuccess(voidApiResponse.getObj());
                    } else {
                        listener.onFailure(voidApiResponse.getEvent(), voidApiResponse.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void createCouponOrderNow(final String loginName, final int couponModelId, final int count, final int channelId, final int plusModelId, final CallbackListener<OrderInfo> listener) {
        new AsyncTask<Void, Void, ApiResponse<OrderInfo>>() {

            @Override
            protected ApiResponse<OrderInfo> doInBackground(Void... voids) {
                return kcuponApi.createCouponOrderNow(loginName, couponModelId, count, channelId, plusModelId);
            }

            @Override
            protected void onPostExecute(ApiResponse<OrderInfo> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void createQrCode(final String loginName, final int couponModelId, final int count, final int channelId, final CallbackListener<VerificationModel> listener) {
        new AsyncTask<Void, Void, ApiResponse<VerificationModel>>() {

            @Override
            protected ApiResponse<VerificationModel> doInBackground(Void... voids) {
                return kcuponApi.createQrCode(loginName, couponModelId, count, channelId);
            }

            @Override
            protected void onPostExecute(ApiResponse<VerificationModel> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void getAddress(final String loginName, final CallbackListener<AddressModel> listener) {
        new AsyncTask<Void, Void, ApiResponse<AddressModel>>() {

            @Override
            protected ApiResponse<AddressModel> doInBackground(Void... voids) {
                return kcuponApi.getAddress(loginName);
            }

            @Override
            protected void onPostExecute(ApiResponse<AddressModel> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void startVerificationDelivery(final int verificatonId, final int provinceId, final String provinceName, final int cityId, final String cityName, final int countyId, final String countyName, final String address, final String addressee, final String linkPhone, final String remark, final CallbackListener<String> listener) {
        new AsyncTask<Void, Void, ApiResponse<String>>() {

            @Override
            protected ApiResponse<String> doInBackground(Void... voids) {
                return kcuponApi.startVerificationDelivery(verificatonId, provinceId, provinceName, cityId, cityName, countyId, countyName, address, addressee, linkPhone, remark);
            }

            @Override
            protected void onPostExecute(ApiResponse<String> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getMsg());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void listCouponWallet(final String loginName, final String keyWords, final int state, final int type, final int currentPage, final int pageSize, final CallbackListener<List<CouponModel>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<CouponModel>>>() {

            @Override
            protected ApiResponse<List<CouponModel>> doInBackground(Void... voids) {
                return kcuponApi.listCouponWallet(loginName, keyWords, state, type, currentPage, pageSize);
            }

            @Override
            protected void onPostExecute(ApiResponse<List<CouponModel>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void cancleOrder(final String orderNumber, final String loginName, final CallbackListener<Void> listener) {
        new AsyncTask<Void, Void, ApiResponse<Void>>() {

            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return kcuponApi.cancleOrder(orderNumber, loginName);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void payByWallet(final String orderNumber, final String loginName, final String payPass, final CallbackListener<OrderInfo> listener) {
        new AsyncTask<Void, Void, ApiResponse<OrderInfo>>() {

            @Override
            protected ApiResponse<OrderInfo> doInBackground(Void... voids) {
                return kcuponApi.payByWallet(orderNumber, loginName, payPass);
            }

            @Override
            protected void onPostExecute(ApiResponse<OrderInfo> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void listOrder(final String loginName, final String keyWords, final String state, final int pageSize, final int currentPage, final CallbackListener<List<OrderModel>> listener) {
        new AsyncTask<Void, Void, ApiResponse<List<OrderModel>>>() {

            @Override
            protected ApiResponse<List<OrderModel>> doInBackground(Void... voids) {
                return kcuponApi.listOrder(loginName, keyWords, state, pageSize, currentPage);
            }

            @Override
            protected void onPostExecute(ApiResponse<List<OrderModel>> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObjList());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void getCustomerWallet(final String loginName, final CallbackListener<WalletModel> listener) {
        new AsyncTask<Void, Void, ApiResponse<WalletModel>>() {

            @Override
            protected ApiResponse<WalletModel> doInBackground(Void... voids) {
                return kcuponApi.getCustomerWallet(loginName);
            }

            @Override
            protected void onPostExecute(ApiResponse<WalletModel> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void getSmsCode4Register(final String phoneNum, final CallbackListener<String> listener) {
        new AsyncTask<Void, Void, ApiResponse<String>>() {
            @Override
            protected ApiResponse<String> doInBackground(Void... voids) {
                return kcuponApi.getSmsCode4Register(phoneNum);
            }

            @Override
            protected void onPostExecute(ApiResponse<String> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(response.getObj());
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void sendSmsCode(final String phoneNum, final CallbackListener<Void> listener) {
        // 参数检查
        if (TextUtils.isEmpty(phoneNum)) {
            listener.onFinish();
            listener.onFailure(ReturnCode.C_PARAM_NULL, "请输入手机号码");
            return;
        }
        Pattern pattern = Pattern.compile("1\\d{10}");
        Matcher matcher = pattern.matcher(phoneNum);
        if (!matcher.matches()) {
            if (listener != null) {
                listener.onFailure(ErrorEvent.PARAM_ILLEGAL, "手机号不正确");
            }
            return;
        }

        // 请求Api
        new AsyncTask<Void, Void, ApiResponse<Void>>() {
            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return kcuponApi.sendSmsCode4Register(phoneNum);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    @Override
    public void sendSmsCode4ResetPassword(final String phoneNum, final CallbackListener<Void> listener) {
        // 参数检查
        if (TextUtils.isEmpty(phoneNum)) {
            listener.onFinish();
            listener.onFailure(ReturnCode.C_PARAM_NULL, "请输入手机号码");
            return;
        }
        Pattern pattern = Pattern.compile("1\\d{10}");
        Matcher matcher = pattern.matcher(phoneNum);
        if (!matcher.matches()) {
            if (listener != null) {
                listener.onFailure(ErrorEvent.PARAM_ILLEGAL, "手机号不正确");
            }
            return;
        }

        // 请求Api
        new AsyncTask<Void, Void, ApiResponse<Void>>() {
            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                return kcuponApi.sendSmsCode4GetLoginPassword(phoneNum);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public void loginByApp(final String loginName, final String password, final CallbackListener<Void> listener) {
        // 参数检查
        if (TextUtils.isEmpty(loginName)) {
            if (listener != null) {
                listener.onFailure(ErrorEvent.PARAM_NULL, "请输入手机号码");
            }
            return;
        }
        if (TextUtils.isEmpty(password) || password.length() > 15 || password.length() < 6) {
            if (listener != null) {
                listener.onFailure(ErrorEvent.PARAM_NULL, "请输入6-15位密码");
            }
            return;
        }
        Pattern p = Pattern.compile(REG);
        Matcher m = p.matcher(loginName);
        if (!m.find()) {
            listener.onFinish();
            listener.onFailure(ReturnCode.C_PARAM_NULL, "请输入正确的手机号码");
            return;
        }

        // 请求Api
        new AsyncTask<Void, Void, ApiResponse<Void>>() {
            @Override
            protected ApiResponse<Void> doInBackground(Void... voids) {
                TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//                String imei = telephonyManager.getDeviceId();
                String appleToken = "123";
                String imei = "123";
                return xyApi.loginByApp(loginName, password, LOGIN_OS, imei, appleToken);
            }

            @Override
            protected void onPostExecute(ApiResponse<Void> response) {
                if (listener != null && response != null) {
                    if (response.isSuccess()) {
                        listener.onSuccess(null);
                    } else {
                        listener.onFailure(response.getEvent(), response.getMsg());
                    }
                }
            }
        }.execute();
    }

    public NetworkTask<List<CouponStore>> listCouponStore(final int couponModelId, CallbackListener<List<CouponStore>> callbackListener) {
        if (couponModelId <= 0) {
            callbackListener.onFinish();
            callbackListener.onFailure(ReturnCode.C_PARAM_NULL, "券ID不正确");
            return null;
        }
        NetworkTask<List<CouponStore>> task = new NetworkTask<List<CouponStore>>(callbackListener) {
            @Override
            public ApiResponse<List<CouponStore>> run() {
                ApiResponse<List<CouponStore>> response = null;
                response = kcuponApi.listCouponStore(couponModelId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    //根据分类查询券列表
    @Override
    public NetworkTask<List<CouponBO>> listCouponModel(final String keyword, final int modelType, final int listType, final int industryId, final int currentPage, final int pageSize, final int locationId, CallbackListener<List<CouponBO>> callbackListener) {
        // 调用API之前的检查
        if (industryId < 0) {
            callbackListener.onFinish();
            callbackListener.onFailure(ReturnCode.C_PARAM_NULL, "行业ID不正确");
            return null;
        }
        if (currentPage < 0) {
            callbackListener.onFinish();
            callbackListener.onFailure(ReturnCode.C_PARAM_ERROR, "当前页数小于0");
            return null;
        }

        NetworkTask<List<CouponBO>> task = new NetworkTask<List<CouponBO>>(callbackListener) {
            @Override
            public ApiResponse<List<CouponBO>> run() {
                ApiResponse<List<CouponBO>> response = null;
                response = kcuponApi.listCouponModel(keyword, modelType, listType, industryId, currentPage, pageSize, locationId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<String> createCouponPackageOrder(final String loginName, final String couponPackageId, CallbackListener<String> callbackListener) {
        // 调用API之前的检查
        if (TextUtils.isEmpty(loginName)) {
            callbackListener.onFinish();
            callbackListener.onFailure(ReturnCode.C_PARAM_NULL, "用户名为空");
            return null;
        }
        if (TextUtils.isEmpty(couponPackageId)) {
            callbackListener.onFinish();
            callbackListener.onFailure(ReturnCode.C_PARAM_ERROR, "礼包ID为空");
            return null;
        }

        NetworkTask<String> task = new NetworkTask<String>(callbackListener) {
            @Override
            public ApiResponse<String> run() {
                ApiResponse<String> response = null;
                response = kcuponApi.createCouponPackageOrder(loginName, couponPackageId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<OrderInfo> addFreeCoupon(final int couponModelId, final String loginName, final int count, final int channelId, CallbackListener<OrderInfo> callbackListener) {
        if (couponModelId <= 0) {
            callbackListener.onFinish();
            callbackListener.onFailure(ReturnCode.C_PARAM_NULL, "券ID不正确");
            return null;
        }
        NetworkTask<OrderInfo> task = new NetworkTask<OrderInfo>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.addFreeCoupon(loginName, couponModelId, count, channelId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<List<CouponBO>> getTopicItemDetail(final String topicId, CallbackListener<List<CouponBO>> callbackListener) {
        if (TextUtils.isEmpty(topicId)) {
            callbackListener.onFinish();
            callbackListener.onFailure(ReturnCode.C_PARAM_NULL, "专题ID不正确");
            return null;
        }
        NetworkTask<List<CouponBO>> task = new NetworkTask<List<CouponBO>>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = xyApi.getTopicItemDetail(topicId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public void listCustomerCoupons(final String customerId, final int currentPage, CallbackListener<List<CustomerCouponBO>> callbackListener) {
        NetworkTask<List<CustomerCouponBO>> task = new NetworkTask<List<CustomerCouponBO>>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.listCustomerCouponsForPage(customerId, null, currentPage, PAGE_SIZE);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    @Override
    public void listRecommendCoupons(final String customerId, CallbackListener<List<CustomerCouponBO>> callbackListener) {
        NetworkTask<List<CustomerCouponBO>> task = new NetworkTask<List<CustomerCouponBO>>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.listRecommendCoupons(customerId);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    @Override
    public void viewCustomerCoupon(final int id, CallbackListener<CustomerCouponBO> callbackListener) {
        NetworkTask<CustomerCouponBO> task = new NetworkTask<CustomerCouponBO>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.viewCustomerCouponById(id);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    @Override
    public void listMyReceiveCoupons(final String customerId, final int orderState, final int currentPage, CallbackListener<List<CustCouponOrderBO>> callbackListener) {
        NetworkTask<List<CustCouponOrderBO>> task = new NetworkTask<List<CustCouponOrderBO>>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.listMyReceivedOrder(customerId, orderState, currentPage, PAGE_SIZE);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    public NetworkTask<Boolean> updateCustomer(final String obj, CallbackListener<Boolean> callbackListener) {
        NetworkTask<Boolean> task = new NetworkTask<Boolean>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = xyApi.updateCustomer(obj);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<CustomerBO> checkCustExist(final String loginName, CallbackListener<CustomerBO> callbackListener) {
        NetworkTask<CustomerBO> task = new NetworkTask<CustomerBO>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.checkCustExist(loginName);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<Map<String, List<CouponModel>>> getPreferentialCoupon(final String loginName, final int cashModelId, final int count, CallbackListener<Map<String, List<CouponModel>>> callbackListener) {
        NetworkTask<Map<String, List<CouponModel>>> task = new NetworkTask<Map<String, List<CouponModel>>>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.getPreferentialCoupon(loginName, cashModelId, count);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<String> createCustomerOrder(final String phone, final String payPass, final int couponId, final int count, CallbackListener<String> callbackListener) {
        NetworkTask<String> task = new NetworkTask<String>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = xyApi.createCustomerOrder(phone, couponId, payPass, count);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public void listMyPublishedCoupons(final String customerId, final String state, final int currentPage, CallbackListener<List<CustomerCouponBO>> callbackListener) {
        NetworkTask<List<CustomerCouponBO>> task = new NetworkTask<List<CustomerCouponBO>>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.listMyCustomerCoupon(customerId, state, currentPage, PAGE_SIZE);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    @Override
    public NetworkTask<List<MessageBO>> queryInmessage(final String phone, final int currentPage, final int pageSize, final String state, CallbackListener<List<MessageBO>> callbackListener) {
        NetworkTask<List<MessageBO>> task = new NetworkTask<List<MessageBO>>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.queryInmessage(phone, currentPage, pageSize, state);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<Map<String, Object>> calcPrice(final String loginName, final int buyModelId, final int buyModelCnt, final int usePlusModelId, CallbackListener<Map<String, Object>> callbackListener) {
        NetworkTask<Map<String, Object>> task = new NetworkTask<Map<String, Object>>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.calcPrice(loginName, buyModelId, buyModelCnt, usePlusModelId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<Double> calcCustCouponPrice(final int custCouponId, final int count, CallbackListener<Double> callbackListener) {
        NetworkTask<Double> task = new NetworkTask<Double>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = xyApi.calcCustCouponPrice(custCouponId, count);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<List<CouponBO>> searchCoupon4Page(final String xyCustomerId, final String category, final String searchKey, final int currentPage, final int pageSize, CallbackListener<List<CouponBO>> callbackListener) {
        NetworkTask<List<CouponBO>> task = new NetworkTask<List<CouponBO>>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = xyApi.searchCoupon4Page(xyCustomerId, category, searchKey, currentPage, pageSize);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<CustomerIncomeBO> queryXyIncome(final String customerId, CallbackListener<CustomerIncomeBO> callbackListener) {
        NetworkTask<CustomerIncomeBO> task = new NetworkTask<CustomerIncomeBO>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = xyApi.queryXyIncome(customerId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<Void> readMessage(final String loginName, final int msgId, CallbackListener<Void> callbackListener) {
        NetworkTask<Void> task = new NetworkTask<Void>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.readMessage(loginName, msgId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<Integer> realnameAuth(final String loginName, final String realname, final String idnum, final String idPicUrl, final String idBackPicUrl, CallbackListener<Integer> callbackListener) {
        NetworkTask<Integer> task = new NetworkTask<Integer>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.realnameAuth(loginName, realname, idnum, idPicUrl, idBackPicUrl);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<String> payAppOrderByWX(final String orderNumber, final String mchId, final String appId, CallbackListener<String> callbackListener) {
        NetworkTask<String> task = new NetworkTask<String>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.payAppOrderByWX(orderNumber, mchId, appId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<OrderInfo> createCustomerOrderByAliPay(final String phone, final int couponId, final int count, CallbackListener<OrderInfo> callbackListener) {
        NetworkTask<OrderInfo> task = new NetworkTask<OrderInfo>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = xyApi.createCustomerOrderByAliPay(phone, couponId, count);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<OrderInfo> createCustomerOrderByWxPay(final String phone, final int couponId, final int count, final String appId, final String mchId, CallbackListener<OrderInfo> callbackListener) {
        NetworkTask<OrderInfo> task = new NetworkTask<OrderInfo>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = xyApi.createCustomerOrderByWxPay(phone, couponId, count, appId, mchId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public NetworkTask<Boolean> makeOrderToPaying(final String orderId, CallbackListener<Boolean> callbackListener) {
        NetworkTask<Boolean> task = new NetworkTask<Boolean>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse response = null;
                response = kcuponApi.makeOrderToPaying(orderId);
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
        return task;
    }

    @Override
    public void activateCoupon(final int couponId, CallbackListener<Boolean> callbackListener) {
        NetworkTask<Boolean> task = new NetworkTask<Boolean>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.activateCoupon(couponId);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    @Override
    public void inactivateCoupon(final int couponId, CallbackListener<Boolean> callbackListener) {
        NetworkTask<Boolean> task = new NetworkTask<Boolean>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.inactivateCoupon(couponId);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    @Override
    public void listMyOrders(final int type, final String customerId, final int currentPage, CallbackListener<List<CustCouponOrderBO>> callbackListener) {
        NetworkTask<List<CustCouponOrderBO>> task = new NetworkTask<List<CustCouponOrderBO>>(callbackListener) {
            @Override
            public ApiResponse run() {
                ApiResponse<List<CustCouponOrderBO>> response = null;
                switch (type) {
                    case 0:
                        response = xyApi.myUnfinishedOrder(customerId, currentPage, PAGE_SIZE);
                        break;
                    case 1:
                        response = xyApi.myFinishedOrder(customerId, currentPage, PAGE_SIZE);
                        break;
                    case 2:
                        response = xyApi.myCanceledOrder(customerId, currentPage, PAGE_SIZE);
                        break;
                }
                return response;
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);

        } else {
            task.execute();
        }
    }

    @Override
    public void confirmOrder(final int orderId, CallbackListener<Boolean> callbackListener) {
        NetworkTask<Boolean> task = new NetworkTask<Boolean>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.confirmOrder(orderId);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    @Override
    public void cancelOrder(final int orderId, final String customerId, CallbackListener<Boolean> callbackListener) {
        NetworkTask<Boolean> task = new NetworkTask<Boolean>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.cancelOrder(orderId, customerId);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }

    @Override
    public void changeOrderPrice(final String customerId, final int orderId, final double realPrice, CallbackListener<Boolean> callbackListener) {
        NetworkTask<Boolean> task = new NetworkTask<Boolean>(callbackListener) {
            @Override
            public ApiResponse run() {
                return xyApi.changeOrderPrice(customerId, orderId, realPrice);
            }
        };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        } else {
            task.execute();
        }
    }
}
